<template>
    <div class="layout">
        <!-- 顶部标签 -->
        <app-header class="head">
            <template v-slot:head-title>
                <span>关注</span>
            </template>
        </app-header>

        <!-- 主要内容 -->
        <div class="main">
            <div class="follow">
                <ul>
                    <li v-for="(item, index) in res" :key="item.id">
                        <router-link :to="{path:'/games/detail', query:{id:item.id}}">
                            <div class="pic" :style="{'background-image':'url('+item.src+')'}"></div>
                            <div class="content">
                                <div class="title">{{item.name}}</div>
                                <ol class="tab">
                                    <li v-for="(item2, index2) in res[index].tab" :key="index2"
                                    :style="{'background-color':tabColor[index2]}">{{item2}}</li>
                                </ol>
                                <span class="discount" v-if="item.dis">正在打折</span>
                            </div>
                            <div class="icon">
                                <img src="../assets/ui/arrow_right.png">
                            </div>
                        </router-link>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 底部标签 -->
        <footer>
            <div class="foot">
                <p>我的底线就到这了哇~</p>
            </div>
        </footer>
    </div>
</template>

<script>
import appHeader from '@/components/app-header.vue'
import {gameArray} from '@/assets/data/game.js'

export default {
    name: "Follow",
    components: {
        appHeader,
    },
    data() {
        return {
            arr: gameArray,
            res: [],
            tabColor: [
                "#008000",
                "#FF8C00",
                "#800080",
                "#1D8B73",
                "#8B0000",
                "#FFD700",
            ]
        }
    },
    created() {
        this.arr.forEach((item, index) => {
        let obj = {}
            if (item.like == true) {
                obj.name = item.name;
                obj.src = item.src;
                obj.tab = item.tab;
                obj.dis = item.dis;
                obj.like = item.like;
                obj.id = index;
                this.res.push(obj);
            }
            if (localStorage.getItem('id'+index)) {
                obj.name = item.name;
                obj.src = item.src;
                obj.tab = item.tab;
                obj.dis = item.dis;
                obj.like = true;
                obj.id = index;
                this.res.unshift(obj);
            }
        })

        // 接收详情页兄弟传值
        // Brige.$on('LikeData', data => {
        //     this.res = data;
        //     console.log(this.res);
        // })
    },
}
</script>

<style lang="scss" scoped>
.layout {
    width: 100%;
    overflow: hidden;
    background-color: #2E2E2E;
    .main {
        width: 100%;
        margin-top: 80px;
        .follow {
            width: 100%;
            ul {
                width: 100%;
                padding: 15px 15px 0 15px;
                box-sizing: border-box;
                >li {
                    width: 100%;
                    padding: 10px;
                    box-sizing: border-box;
                    border-radius: 10px;
                    background-color: #111;
                    margin-bottom: 15px;
                    position: relative;
                    a {
                        display: flex;
                        .pic {
                            width: 80px;
                            height: 120px;
                            margin-right: 10px;
                            border-radius: 5px;
                            background-size: cover;
                            background-repeat: no-repeat;
                            flex-shrink: 0;
                        }
                        .content {
                            flex-grow: 1;
                            .title {
                                width: 90%;
                                font-size: 18px;
                                overflow: hidden;
                                text-overflow: ellipsis;
                                white-space: nowrap;
                                color: white;
                            }
                            ol {
                                width: 75%;
                                margin-top: 15px;
                                overflow: hidden;
                                display: flex;
                                flex-wrap: wrap;
                                justify-content: start;
                                align-items: flex-start;
                                li {
                                    height: 20px;
                                    font-size: 12px;
                                    margin-right: 5px;
                                    margin-bottom: 8px;
                                    padding: 2px 5px;
                                    border-radius: 2px;
                                    box-sizing: border-box;
                                    flex-shrink: 0;
                                    color: white;
                                    // background-color: #008000;
                                }
                            }
                            .discount {
                                font-size: 15px;
                                color: red;
                                position: absolute;
                                bottom: 10px;
                            }
                        }
                        .icon {
                            width: 20px;
                            height: 20px;
                            position: absolute;
                            margin-top: -10px;
                            top: 50%;
                            right: 5px;
                            img {
                                width: 20px;
                                height: 20px;
                            }
                        }
                    }
                }
            }
        }
    }
    footer {
        width: 100%;
        height: 160px;
        padding-top: 30px;
        box-sizing: border-box;
        .foot {
            height: 50px;
            line-height: 50px;
            background-color: black;
            color: #999;
            display: flex;
            justify-content: center;
            align-items: baseline;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
        }
    }
}
</style>
